package com.jinhua.admin.controller;
import com.jinhua.admin.service.ProductService;
import com.jinhua.config.IdUtil;
import com.jinhua.config.PaginationRequest;
import com.jinhua.config.Response;
import com.jinhua.admin.service.AdminUserService;
import com.jinhua.admin.vo.AdminUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestBody;
import javax.validation.Valid;

/**
* 后台用户的操作接口
*/
@RestController
@RequestMapping("adminUser")
public class AdminUserController {@Autowired
    private AdminUserService adminUserService;
    
    /**
    * 添加或者修改后台用户 
    *
    * @return
    */
    @PostMapping("save")
    public Response saveAdminUser(@RequestBody AdminUserVo adminUserVo) {
        if (adminUserVo == null) {
            return Response.error();
        }
        return Response.success(adminUserService.saveAdminUser(adminUserVo));
    }
    
    /**
    * 删除后台用户 
    *
    * @param ids 后台用户的Id的集合,例如1,2,3多个用英文,隔开 
    
    * @return
    */
    @RequestMapping("del")
    public Response delAdminUser(Long[] ids) {
        if (ids == null || ids.length == 0) {
            return Response.error();
        }
        return Response.success(adminUserService.delAdminUserByIds(ids));
    }
    
    /**
    * 查找后台用户 
    *
    * @return
    */
    @RequestMapping("find")
    public Response findAdminUser(@RequestBody @Valid PaginationRequest<AdminUserVo> request ) {
        if (request == null) {
            return Response.error();
        }
        AdminUserVo  adminUserVo = request.getQueryCriteria();
        if(adminUserVo.getId()!=null){
            return Response.success(adminUserService.findAdminUserById(adminUserVo.getId()));
        }
        return Response.success(adminUserService.findAdminUserByAll(request));
    }
}
